﻿using System.Reflection;

namespace AbpCodeGenerater.Core
{
    public static class TemplateFuns
    {
        public static string ToDeclareText(Type type)
        {
            return type.ToDeclareText();
        }

        public static string ToDtoDeclareText(Type type)
        {
            return type.ToDtoDeclareText();
        }

        public static List<PropertyInfo> ExcludePropertys(List<PropertyInfo> properties, params string[] excludeProperty)
        {
            return properties.ExcludePropertys(excludeProperty);
        }

        public static List<PropertyInfo> ExcludeExtensiblePropertys(List<PropertyInfo> properties)
        {
            return properties.ExcludeExtensiblePropertys();
        }

        public static List<PropertyInfo> ExcludeConcurrencyStamp(List<PropertyInfo> properties)
        {
            return properties.ExcludeConcurrencyStamp();
        }

        public static List<string> ExcludeUsings(List<string> usings, params string[] excludeUsing)
        {
            return usings.ExcludeUsings(excludeUsing);
        }

        public static List<string> GetNavigationPropertyUsings(List<PropertyInfo> properties, string namespaces, params string[] excludePropertys)
        {
            var navigationPropertyUsings = new List<string>();

            foreach (var navigationProperty in properties.ExcludePropertys(excludePropertys))
            {
                navigationPropertyUsings.AddRange(navigationProperty.PropertyType.GetUsings().ExcludeUsings(namespaces));
            }

            return navigationPropertyUsings;
        }

        public static string GetPropertySummary(Dictionary<string, string> propertySummaries, PropertyInfo property)
        {
            if (!propertySummaries.Keys.Any(x => x == property.Name)) return string.Empty;

            return propertySummaries[property.Name];
        }

        public static string ToCamelCase(string str)
        {
            return str.ToCamelCase();
        }

        public static string ToKebabCase(string str)
        {
            return str.ToKebabCase();
        }

        //public static string GetNullableType(string typeName)
        //{
        //    return typeName.ToNullableType();
        //}

        //public static string ToIsNullExpression(Property property)
        //{
        //    return property.ToIsNullExpression();
        //}

        //public static bool IsNavigation(Property property, IList<Property> properties)
        //{
        //    return property.IsNavigation(properties);
        //}

        //public static bool IsDateTime(Property property)
        //{
        //    if (property == null) return false;
        //    if (property.Type.ToNullableType() == "DateTime?")
        //    {
        //        return true;
        //    }
        //    return false;
        //}

        //public static string GetQueryParamStr(Property property)
        //{
        //    if (property.Type.ToNullableType() == "DateTime?")
        //    {
        //        return $"{property.Type.ToNullableType()} {property.Name.ToCamelCase()} = null,\r\n{property.Type.ToNullableType()} {property.Name.ToCamelCase()}_End = null,";
        //    }
        //    else
        //    {
        //        return $"{property.Type.ToNullableType()} {property.Name.ToCamelCase()} = null,";
        //    }
        //}

        //public static string GetQueryWhereStr(Property property)
        //{
        //    if (property.Type.ToNullableType() == "DateTime?")
        //    {
        //        return $".WhereIf({property.ToIsNullExpression()}, x => x.{property.Name} >= {property.Name.ToCamelCase()})\r\n.WhereIf({property.ToIsNullExpression("_End")}, x => x.{property.Name} <= {property.Name.ToCamelCase()}_End)";
        //    }
        //    else
        //    {
        //        return $".WhereIf({property.ToIsNullExpression()}, x => x.{property.Name} == {property.Name.ToCamelCase()})";
        //    }
        //}

        //public static string GetQueryRequestDtoPropertyStr(Property property)
        //{
        //    if (property.Type.ToNullableType() == "DateTime?")
        //    {
        //        return $"public {property.Type.ToNullableType()} {property.Name} {{ get; set; }}\r\npublic {property.Type.ToNullableType()} {property.Name}_End {{ get; set; }}";
        //    }
        //    else
        //    {
        //        return $"public {property.Type.ToNullableType()} {property.Name} {{ get; set; }}";
        //    }
        //}

        //public static string GetQueryInputParamStr(Property property)
        //{
        //    if (property.Type.ToNullableType() == "DateTime?")
        //    {
        //        return $"input.{property.Name},\r\ninput.{property.Name}_End,";
        //    }
        //    else
        //    {
        //        return $"input.{property.Name},";
        //    }
        //}
    }
}
